import { Component, OnInit } from '@angular/core'
import { JsonApiService } from 'app/core/api/json-api.service' //http请求配置引入

@Component({
  selector: 'sa-repaired-delete-log',
  templateUrl: './repaired-delete-log.component.html'
})
export class RepairedDeleteLogComponent implements OnInit {
  resultTableData: any[] = [] //客户端分页数据暂存
  totalCount: number = 0 //分页总条数
  curPage: number = 1 //分页当前页
  pageSize: number = 10 //内置的分页每页条数
  searchKey: string = '' //搜索keyword
  startTime: string = '' //开始时间
  endTime: string = '' //结束时间
  carNumber: string = '' //车牌号码
  deviceId: string = '' //设备ID，车牌ID
  timeType = '1' // 时间类型

  selectedCompanyId: string = ''
  selectedCompanyName: string = ''
  constructor(private jsonApiService: JsonApiService) {}

  // 接收子组件传递过来的数据
  getSelectTableTime(time) {
    this.startTime = time.startTime
    this.endTime = time.endTime
    this.load()
  }
  //公司选中车牌号回调
  companySelected(data) {
    this.deviceId = data.deviceId
    this.selectedCompanyId = data.companyId
    this.selectedCompanyName = data.companyName
    this.carNumber = data.carNumber
  }
  //刷新
  refresh() {
    this.load()
  }
  ngOnInit() {
    // this.load();
  }
  //查询
  search_data() {
    this.curPage = 1
    this.load()
  }
  //加载list数据
  load() {
    var data = {
      pageSize: this.pageSize,
      nowPage: this.curPage,
      parameters: {
        startTime: this.startTime,
        endTime: this.endTime,
        companyId: this.selectedCompanyId,
        searchKey: this.searchKey,
        deviceId: this.deviceId,
        timeType: this.timeType
      }
    }
    let reqdata = 'gridPager=' + JSON.stringify(data)
    this.jsonApiService.http('logForDeviceRepair/LogForDeviceRepairList.html', reqdata).subscribe(result => {
      this.resultTableData = result.exhibitDatas
      this.totalCount = result.recordCount
    })
  }
  table_search() {
    this.curPage = 1
    this.searchKey = common.stringTrim(this.searchKey)
    this.load()
  }
  //删除所选时间
  del_date() {
    this.startTime = ''
    this.endTime = ''
  }

  //分页回调
  paginate(e) {
    this.curPage = e.page + 1
    this.pageSize = e.rows
    this.load()
  }
}
